package com.dhms.vostok1.data

import com.dhms.uikit.select_bottom_sheet.SelectItem
import com.dhms.vostok1.data.abnormals.*
import com.dhms.vostok1.data.fault.FaultListItemData
import com.dhms.vostok1.data.message_center.MessageCenterData
import com.dhms.vostok1.data.spot_patrol.AbnormalOssData
import com.dhms.vostok1.data.spot_patrol.CompanyCategoyData
import com.dhms.vostok1.data.spot_patrol.TaskData
import com.dhms.vostok1.data.spot_patrol.TaskGroupData
import com.squareup.moshi.Json


const val DEFAULT_PAGE_LIMIT = 10
const val DEFAULT_PAGE_OFFSET = 1

interface BasePageQueryData {
    val offset: Int
    val limit: Int
}

interface PrimaryPageQueryData {
    val page: Int
    @Json(name = "per_page")
    val perPage: Int
}

data class PrimaryBaseListData<T>(
    val items: List<T>,
    val page: Int?,
    val per_page: Int?,
    val total: Int?
)

data class SecondaryBaseListData<T>(
    val data: List<T>,
    val offset: Int?,
    val limit: Int?,
    val total: Int?
)

//data class RelatedFaultListData<T>(
//    @Json(name = "faults") val data: List<T>,
//    val offset: Int,
//    val limit: Int,
//    val total: Int?
//)

data class LoginReqBody(
    @Json(name = "username") val userName: String,
    val password: String,
    val platform: String,
    val project_name: String,
    val prvset_name: String,
)

data class LoginData(
    @Json(name = "uid") val userId: Long?,
    @Json(name = "phone") val userPhone: String?,
    @Json(name = "name") val userName: String?,
    @Json(name = "platform") val userPlatForm: String?,
    @Json(name = "cu_id") val cuId: Long?,
    @Json(name = "cu_services") val cuServices: String?,
    @Json(name = "ro") val userRo: List<Any>?,
    @Json(name = "ob") val userOb: List<Any>?,
    @Json(name = "cc") val userCc: Int?,
    @Json(name = "prvset_name") val userPrvsetName: String?,
    @Json(name = "ent_group_code") val userEntGroupCode: String?,
    @Json(name = "createtime") val userCreatedTime: String?,
)

data class UserOrganizationInfo(
    val organizationId: Long?,
    val organizationInfo: String?
)

data class LocalUserInfoData(
    val userPhone: String? = null,
    val password: String? = null,
    val token: String? = null,
    var avatar: String? = null,
    var username: String? = null,
    var cuName: String? = null,
    var userId: Long? = null,
    var organizationId: Long? = null,
    var originLoginData: String? = null,
    var originAclData: String? = null,
    var privileges: String? = null
)

data class CustomerSelfInfo(
    @Json(name = "adminRoleId") val adminRoleId: Long?,
    @Json(name = "cu_address") val cuAddress: String?,
    @Json(name = "cu_area_code") val cuAreaCode: String?,
    @Json(name = "cu_city_code") val cuCityCode: String?,
    @Json(name = "cu_contact_name") val cuContactName: String?,
    @Json(name = "cu_description") val cuDescription: String?,
    @Json(name = "cu_expires") val cuExpires: String?,
    @Json(name = "cu_id") val cuId: Long,
    @Json(name = "cu_is_enabled") val cuIsEnabled: String?,
    @Json(name = "cu_kind") val cuKind: String?,
    @Json(name = "cu_latitude") val cuLatitude: String?,
    @Json(name = "cu_licence") val cuLicence: Int?,
    @Json(name = "cu_logo") val cuLogo: String?,
    @Json(name = "cu_longitude") val cuLongitude: String?,
    @Json(name = "cu_marked_words") val cuMarkedWords: String?,
    @Json(name = "cu_name") val cuName: String,
    @Json(name = "cu_parent") val cuParent: Long?,
    @Json(name = "cu_province_code") val cuProvinceCode: String?,
    @Json(name = "cu_root_logo") val cuRootLogo: String?,
    @Json(name = "cu_services") val cuServices: String?,
    @Json(name = "cu_size") val cuSize: Int?,
    @Json(name = "cu_system_name") val cuSystemName: String?,
    @Json(name = "cu_tel") val cuTel: String?,
    @Json(name = "cu_trade_id") val cuTradeId: Int?,
    @Json(name = "ent_group_code") val entGroupCode: String?,
    @Json(name = "parent_name") val parentName: String?,
)

data class UserInfoData(
    @Json(name = "ent_group_code") val entGroupCode: String?,
    @Json(name = "roles") val usRoles: String?,
    @Json(name = "us_avatar") val usAvatar: String?,
    @Json(name = "us_id") val usId: Long?,
    @Json(name = "us_is_enabled") val usIsEnabled: String?,
    @Json(name = "us_mail") val usMail: String?,
    @Json(name = "us_name") val usName: String?,
    @Json(name = "us_phone") val usPhone: String?,
    @Json(name = "us_staff_number") val usStaffNumber: String?,
)

class LoginResData(
    val status: Double?,
    val message: String?,
    val code: Int?,
    val data: LoginData?,
    @Json(name = "ref_data") val refData: Map<String, Any>?
)

typealias UserInfoResData = BaseResData<UserInfoData>

enum class ApiState {
    DONE, ERROR, LOADING
}

data class ApiResult(
    val state: ApiState,
    val message: String? = null,
)

data class VerifyCodeReqBody(
    val phone: String,
)

typealias VerifyCodeResData = BaseResData<Any?>

data class CheckVerifyCodeReqBody(
    val phone: String,
    val code: String
)

typealias CheckVerifyCodeResData = BaseResData<Any?>

data class ResetPasswordReqBody(
    val phone: String,
    val code: String,
    val password: String
)

typealias ResetPasswordResData = BaseResData<Any?>

data class MessageLoginReqBody(
    val phone: String,
    val code: String,
)

typealias CustomerInfoResData = BaseResData<CustomerSelfInfo>
typealias TaskResData = BaseResData<TaskData>
typealias TaskGroupResData = BaseResData<TaskGroupData>
typealias CompanyCategoyResData = BaseResData<List<CompanyCategoyData>>
typealias DeviceFaultListResData = BaseResData<SecondaryBaseListData<FaultListItemData>>


typealias AbnormalsResData = BaseResData<PrimaryBaseListData<SpotAbnormalOverviewData>>
typealias AbnormalItemsResData = BaseResData<PrimaryBaseListData<SpotAbnormalItemData>>
typealias AbnormalDetailResData = BaseResData<SpotAbnormalData>
typealias MessageCenterListResData = BaseResData<SecondaryBaseListData<MessageCenterData>>

data class TaskGroupsResData(
    val data: List<TaskGroupData>?,
    val offset: Int?,
    val limit: Int?,
    val total: Int?
)

typealias TaskUpdateReqBody = TaskData

data class TaskExecutorsReqBody(
    val task_executors: List<TaskExecutorsData>
)

data class TaskExecutorsData(
    val task_id: Int,
    val executors: List<SelectItem>
)

data class AbnormalsReqBody(
    val page: Int,
    val per_page: Int = 10,
    val start_time: Long? = null,
    val end_time: Long? = null,
    val device_ids: String? = null,
    val status: String? = null,
    val source: SpotSource? = null
)

data class AbnormalItemsReqBody(
    val name: String
)


data class AbnormalsCreateReqBody(
    //设备ID
    val device_id: Long,
    //设备名称
    val device_name: String,
    //异常项名称 [异常项]
    val name: String,
    //异常描述
    val desc: String? = null,
    //异常照片/视频，附件
    val osss: List<AbnormalOssData>? = null,
    //异常上报的来源
    val source: SpotSource,
    val report_time: Long,
    val report_user_id: Int,
    val report_user_name: String
)

data class AbnormalsUpdateReqBody(
    val id: String,
    val handle_desc: String,
    val status: FaultState,
    val source: SpotSource,
    val handle_user_id: Int,
    val handle_user_name: String
)

data class FaultProcessReqBody(
    val ids: String,
    val description: String,
    val type: FaultState
)

data class UploadFileResData(
    val local: Boolean?,
    val name: String?,
    @Json(name = "ref_id") val refId: String?,
    val size: Long?,
    val thumb: String?
)


data class MessageTotalResData(
    val total: Int?
)

data class VibTransitionData(
    val id: String = "e5871da53c1c421d8051a44eca75920d",
    val previous: String = "none",
    val transition: String = "calc",
    val visible: Boolean = true,
    val parameters: Map<String, Int> = mapOf("peaks" to 10)
)

data class VibAnalyseReqBody(
    val files: List<String>,
    @Json(name = "no_centralize") val noCentralize: Boolean = false,
    val precision: Int = 8,
    @Json(name = "skip_src") val skipSrc: Boolean = false,
    val window: String = "Rect",
    val transitions: List<VibTransitionData> = listOf(VibTransitionData())
)